﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

class Base64
{
    public static void ConvertToBase64(string inputFileName, string outputFileName)
    {
        StreamReader input = new StreamReader(inputFileName);
        string fileContent;
        using (input)
        {
            fileContent = input.ReadToEnd();
        }
        byte[] inputBytes = Encoding.Default.GetBytes(fileContent);
        string base64string = Convert.ToBase64String(inputBytes);
        StreamWriter output = new StreamWriter(outputFileName);
        using (output)
        {
            output.Write(base64string);
        }
    }

    public static void ConvertFromBase64(string inputFileName, string outputFileName)
    {
        StreamReader input = new StreamReader(inputFileName);
        string fileContent;
        using (input)
        {
            fileContent = input.ReadToEnd();
        }
        byte[] originalBytes = Convert.FromBase64String(fileContent);
        StreamWriter output = new StreamWriter(outputFileName);
        using (output)
        {
            string message = Encoding.Default.GetString(originalBytes);
            output.Write(message);
        }        
    }

    static void Main(string[] args)
    {
        string startingFileName = "test.txt";
        string tempFileName = "temp.out";
        string endFileName = "copy.txt";
        ConvertToBase64(startingFileName,tempFileName);
        ConvertFromBase64(tempFileName, endFileName);
        File.Delete(tempFileName);
    }
}
